function J_x2 = getJacobianNLS(model,x2,t)

if model.modelNum == 1 || model.modelNum == 2
    if model.factorSignResOn == 1
        % With sign restrictions on factors
        x       = [model.macros(t,:)';exp(x2(1:model.nm,1));x2(model.nm+1:end,1);];
        scaling = [ones(1,model.nm),exp(x2(1:model.nm,1))',ones(1,model.nn)];
        J       = (model.gx + 2*model.gxx*kron(eye(model.nx),x)).*repmat(scaling,model.ny,1);
    else
        % No sign restrictions on factors
        x      = [model.macros(t,:)';x2];
        J      = model.gx + 2*model.gxx*kron(eye(model.nx),x);
    end
    J_x2   = J(:,model.nm+1:end);
end